/*
 * Copyright© 2003-2019 浙江汇信科技有限公司, All Rights Reserved.
 */
package com.icinfo.cloud.provider.punish.common.user.service.impl;

import com.icinfo.cloud.common.security.util.UserUtil;
import com.icinfo.cloud.provider.common.constant.Constant;
import com.icinfo.cloud.provider.punish.common.publicsecurityentrust.vo.SendDingMessageVo;
import com.icinfo.cloud.provider.punish.common.user.service.IMemberUserCommonService;
import com.icinfo.cloud.provider.punish.usersign.mapper.MemberUserSignMapper;
import com.icinfo.cloud.xzcf.provider.member.territory.model.MemberTerritory;
import com.icinfo.cloud.xzcf.provider.member.userinfo.dto.UserDTO;
import com.icinfo.framework.core.service.support.MyBatisServiceSupport;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

//import com.icinfo.cloud.provider.punish.api.dto.LawEnforcerDto;
//import com.icinfo.cloud.provider.punish.evideinv.service.EvidenceInventoryService;

/**
 * 描述: 用户签名信息表 member_user_sign 对应的Service接口实现类.<br>
 *
 * @author framework generator
 * @date 2022年07月21日
 */
@Slf4j
@Service
public class MemberUserCommonServiceImpl extends MyBatisServiceSupport implements IMemberUserCommonService {

    @Resource
    private MemberUserSignMapper memberUserSignMapper;

    /**
     * 获取当前用户数据权限，1-本单位 2-本区域
     *
     * @param
     * @return {@link String}
     * @author liyafeng
     * @date 2022/9/5
     */
    @Override
    public String getUserDataPermission() {
        //默认本单位
        String dataPermission = Constant.STRING_1;
        UserDTO userDTO = UserUtil.getUserInfo();
        String orgCode = userDTO.getOrgCode();
        String userId = userDTO.getUserId().toString();
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("userId", userId);
        paramMap.put("orgCode", orgCode);
        //根据用户id与orgCode 查询是否有本区域权限
        int num = memberUserSignMapper.selectAreaDataPermissionNum(paramMap);
        if (num > 0) {
            dataPermission = Constant.STRING_2;
        }
        return dataPermission;
    }

    /**
     * 获取是否展示修改按钮;1 展示 0 不展示
     *
     * @param
     * @return {@link String}
     * @author liyafeng
     * @date 2022/9/5
     */
    @Override
    public String getIsShowEditButton() {
        //默认展示
        String isShowEditButton = Constant.STRING_0;
        UserDTO userDTO = UserUtil.getUserInfo();
        String orgCode = userDTO.getOrgCode();
        String userId = userDTO.getUserId().toString();
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("userId", userId);
        paramMap.put("orgCode", orgCode);
        int num = memberUserSignMapper.selectDeptParamPermissionNum(paramMap);
        if (num > 0) {
            isShowEditButton = Constant.STRING_1;
        }
        return isShowEditButton;
    }

    /**
     * 描述: 查询当前登录人是否有人设条线
     *
     * @return java.lang.Boolean
     * @author zhanghongqiang
     * @Date 2022/10/25
     */
    @Override
    public Boolean getUserHumanSociety(String orgCode) {
        List<MemberTerritory> memberTerritory = memberUserSignMapper.selectUserBars(orgCode);
        if (!ObjectUtils.isEmpty(memberTerritory)) {
            for (MemberTerritory territory : memberTerritory) {
                if (Constant.HUMAN_SOCIETY_BARS_CODE.equals(territory.getCode())) {
                    return true;
                }
            }
        }
        return false;
    }

    @Override
    public List<SendDingMessageVo> getDingIdByOrgCodeAndRoleId(String orgCode, String roleId) {
        return memberUserSignMapper.getDingIdByOrgCodeAndRoleId(orgCode, roleId);
    }
}